package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/testuname")
public class TestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //接收参数
        String userName = req.getParameter("username");


        //设置响应时的页面编码
        resp.setContentType("text/html;charset=utf-8");

        PrintWriter writer = resp.getWriter();

        if ("admin".equals(userName) || "abc".equals(userName) || "Tome".equals(userName)){

            writer.println("账号已被注册");
        }else if ("".equals(userName)){
            writer.println("请输入用户名");
        }
        else{

            writer.println("账户可用");
        }
    }
}
